/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LSBean;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.XBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintX_LSActivity extends AppCompatActivity {
	
	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;

	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_X1 = null;
	private EditText et_X2 = null;
	private EditText et_X3 = null;
	private EditText et_X4 = null;
	private EditText et_X5 = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_x);
		
		btnPrint = (Button) findViewById(R.id.btn_printX_print);
		btnCancel = (Button) findViewById(R.id.btn_printX_cancel);
		
		et_X1 = (EditText) findViewById(R.id.et_print_X1);
		et_X2 = (EditText) findViewById(R.id.et_print_X2);
		et_X3 = (EditText) findViewById(R.id.et_print_X3);
		et_X4 = (EditText) findViewById(R.id.et_print_X4);
		et_X5 = (EditText) findViewById(R.id.et_print_X5);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);


		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iX1 = 0;
				int iX2 = 0;
				int iX3 = 0;
				int iX4 = 0;
				int iX5 = 0;
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				
				if(!("".equals(et_X1.getText().toString()))){
					iX1 = Integer.parseInt(et_X1.getText().toString());
				}
				if(!("".equals(et_X2.getText().toString()))){
					iX2 = Integer.parseInt(et_X2.getText().toString());
				}
				if(!("".equals(et_X3.getText().toString()))){
					iX3 = Integer.parseInt(et_X3.getText().toString());
				}
				if(!("".equals(et_X4.getText().toString()))){
					iX4 = Integer.parseInt(et_X4.getText().toString());
				}
				if(!("".equals(et_X5.getText().toString()))){
					iX5 = Integer.parseInt(et_X5.getText().toString());
				}
				
				int nReturn = 0;
				Intent intent = PrintX_LSActivity.this.getIntent();
				String Order = intent.getStringExtra("Order");
				
				if(Order.equals("X")){
					nReturn = cdf.PTK_DrawRectangle(iX1, iX2, iX3, iX4, iX5);
				} else if (Order.equals("LS")){
					nReturn = cdf.PTK_DrawDiagonal(iX1, iX2, iX3, iX4, iX5);
				}
				
				if (nReturn == 0) {
					if(Order.equals("X")){
						XBean bean = new XBean(iX1, iX2, iX3, iX4, iX5);
						labelBeans.add(bean);
					} else if (Order.equals("LS")){
						LSBean bean = new LSBean(iX1, iX2, iX3, iX4, iX5);
						labelBeans.add(bean);
					}
					Toast.makeText(PrintX_LSActivity.this,  R.string.setting_success,
							Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintX_LSActivity.this,  R.string.setting_fail,
							Toast.LENGTH_SHORT).show();
				}
				
			}
		});
	}
}
